/*********************************************************************\
*
*                  (c) lkc
*                  All Rights Reserved. lkc Confidential
*
\*********************************************************************/
/*********************************************************************\
*   Title                      :
*
*   Module Description         :
*
*   Author                     : lkc
*
*   Created                    : 2018-7-2
*
\*********************************************************************/
#ifndef CAMGAIN_CONTROL_H
#define CAMGAIN_CONTROL_H

class CamGainControl
{
public:
    static CamGainControl& GetInstance();//获取CamControl的实例
    CamGainControl& operator = (const CamGainControl&) = delete;
    CamGainControl(const CamGainControl&) = delete;

private:
    static CamGainControl m_Instance;
    CamGainControl();

public:
//    void MaximizeGain();//相机增益调节到最大
//    void MinimizeGain();//相机增益调节到最小
    void Init();
    void IncGain(const int step = 5);//增大相机增益，步长step，最大100
    void DecGain(const int step = 5);//减小相机增益，步长step，最大100
    void SetGain(const int value);//设置相机增益，范围0～100
    int GetGain();//获取相机当前增益
    void SetGainAutoMode(bool isAuto);
    bool GetCamGainMode();

private:
    void CamGainIicSend(unsigned char high, unsigned char low);
    void GainChipReset();
    void GainChipNormal();

private:
    const static unsigned char GAIN_IIC_ADDR = 0x4c;
    const static int GAIN_IIC_DATA_LEN = 3;
    const static int CAM_GAIN_MIN = 0;
    const static int CAM_GAIN_MAX = 100;
    const static int CAM_GAIN_INIT = 40;
    const float ZERO_GAIN_VOLTAGE = 2.5;     //初始增益电压
    //static const float ZERO_GAIN_VOLTAGE = 0.5;
    const float MAX_GAIN_VOLTAGE = 5;
    const float VOLTAGE_STEP = (MAX_GAIN_VOLTAGE-ZERO_GAIN_VOLTAGE)/CAM_GAIN_MAX;
    const int MAX_IIC_GAIN_DATA = 0xFFFF;
    const int MIN_IIC_GAIN_DATA = int(MAX_IIC_GAIN_DATA*ZERO_GAIN_VOLTAGE/MAX_GAIN_VOLTAGE);
    const float MIN_DATA_STEP = (MAX_IIC_GAIN_DATA-MIN_IIC_GAIN_DATA)/CAM_GAIN_MAX;

    int m_camGain = CAM_GAIN_INIT;
    bool m_gainIsAuto = false;

};


#endif // CAMGAIN_CONTROL_H
/********************************************************************\
 *
 * REVISION RECORDS
 *
\*********************************************************************/
/*********************************************************************/
/*
 *
 *
 *
\*********************************************************************/
/*------------------------------The End------------------------------*/





